part of '../repository.dart';

class _LexicalItemDtoFactory {
  const _LexicalItemDtoFactory._internal();

  static const _instance = _LexicalItemDtoFactory._internal();

  factory _LexicalItemDtoFactory() {
    return _instance;
  }

  _LexicalItemDto fromJson(Map<String, dynamic> json) {
    final String type = json[_kLexicalItemTypeKey];

    switch (type) {
      case _kAdjectiveTypeValue:
        return _InbuiltAdjectiveDto.fromJson(json);
      case _kAdverbTypeValue:
        return _InbuiltAdverbDto.fromJson(json);
      case _kConjunctionTypeValue:
        return _InbuiltConjunctionDto.fromJson(json);
      case _kNounTypeValue:
        return _InbuiltNounDto.fromJson(json);
      case _kNumeralTypeValue:
        return _InbuiltNumeralDto.fromJson(json);
      case _kPrepositionTypeValue:
        return _InbuiltPrepositionDto.fromJson(json);
      case _kPronounTypeValue:
        return _InbuiltPronounDto.fromJson(json);
      case _kVerbTypeValue:
        return _InbuiltVerbDto.fromJson(json);
      case _kPhrasalVerbTypeValue:
        return _InbuiltPhrasalVerbDto.fromJson(json);
      case _kCustomLexicalItemTypeValue:
        return _CustomLexicalItemDto.fromJson(json);
      default:
        throw UnimplementedError();
    }
  }

  _LexicalItemDto fromEntity(LexicalItem lexicalItem) {
    switch (lexicalItem) {
      case InbuiltAdjective():
        return _InbuiltAdjectiveDto.fromEntity(lexicalItem);
      case InbuiltAdverb():
        return _InbuiltAdverbDto.fromEntity(lexicalItem);
      case InbuiltConjunction():
        return _InbuiltConjunctionDto.fromEntity(lexicalItem);
      case InbuiltNoun():
        return _InbuiltNounDto.fromEntity(lexicalItem);
      case InbuiltNumeral():
        return _InbuiltNumeralDto.fromEntity(lexicalItem);
      case InbuiltPreposition():
        return _InbuiltPrepositionDto.fromEntity(lexicalItem);
      case InbuiltPronoun():
        return _InbuiltPronounDto.fromEntity(lexicalItem);
      case InbuiltVerb():
        return _InbuiltVerbDto.fromEntity(lexicalItem);
      case InbuiltPhrasalVerb():
        return _InbuiltPhrasalVerbDto.fromEntity(lexicalItem);
      case CustomLexicalItem():
        return _CustomLexicalItemDto.fromEntity(lexicalItem);
    }
  }
}
